<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>新闻中心</title>
    <link rel="stylesheet" href="../../css/mui.min.css" />
    <link rel="stylesheet" href="../../css/own.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">新闻中心</h1>		
		<a href="javascript:void(0)" class="top-tel" id="telBtn">客服热线</a>
	</header>
<div class="mui-content">
	<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
		<div class="mui-scroll">
			<!--数据列表-->
			<ul class="mui-table-view mui-table-view-chevron newslist">
				<!--<li class="mui-table-view-cell"><a class="mui-navigate-right"><b></b><span>投资达人恒指期货开通夜盘了</span><em>02-28</em></a></li>
				<li class="mui-table-view-cell"><a class="mui-navigate-right nl_read"><b></b><span>投资达人恒指期货开通夜盘了</span><em>02-28</em></a></li>
		-->	</ul>
		</div>
	</div>
</div>
<script type="text/javascript" src="../../js/mui.min.js" ></script>
<script type="text/javascript" src="../../js/common.js"></script>

<script>
	mui.init({
		pullRefresh: {
			container: '#pullrefresh',
			/*down: {
				callback: pulldownRefresh
			},*/
			up: {
				contentrefresh: '正在加载...',
				callback: pullupRefresh
			}
		}
	});
	/**
	 * 下拉刷新具体业务实现
	 */
	/*function pulldownRefresh() {
		setTimeout(function() {
			var table = document.body.querySelector('.mui-table-view');
			var cells = document.body.querySelectorAll('.mui-table-view-cell');
			for (var i = cells.length, len = i + 3; i < len; i++) {
				var li = document.createElement('li');
				li.className = 'mui-table-view-cell';
				li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
				//下拉刷新，新纪录插到最前面；
				table.insertBefore(li, table.firstChild);
			}
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
		}, 1500);
	}*/
	var count = 0;
	var loadsize=10;// 每次上啦加载10条 
	/**
	 * 上拉加载具体业务实现
	 */
	function pullupRefresh() { 
		
		setTimeout(function() {
			var cacheData = tzdr.cacheNews.getData(tzdr.cacheNews.news_data);
			//alert(cacheData);
			if (mui.isnull(cacheData)){
			   	  mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
		  }
		    var cacheJsonData = JSON.parse(cacheData); 
		    var cachedataLen = cacheJsonData.length; 
		   
			var table = document.body.querySelector('.mui-table-view');
			var tempBegin = count;
			var tempEnd = count + loadsize;
			if (tempEnd>=cachedataLen){
			   	  mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
			   	  tempEnd = cachedataLen; 
		    }
			else
			{
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
			}
			
			for (tempBegin; tempBegin < tempEnd; tempBegin++) {
				count++;
				var li = document.createElement('li');
				li.className = 'mui-table-view-cell'; 
				var a_class = 'mui-navigate-right';
				if (tzdr.cacheNews.isread(cacheJsonData[tempBegin].nid)){
					a_class += " nl_read";
				}
				//li.id=cacheJsonData[tempBegin].nid;
				li.innerHTML = '<a class="'+a_class+'" id="'+cacheJsonData[tempBegin].nid+'"   href="javascript:void(0);"><b></b><span>'+cacheJsonData[tempBegin].title+'</span><em>'+cacheJsonData[tempBegin].issueDate+'</em></a>';
				table.appendChild(li);  
			}
			
		}, 1500);
		

		//监听新闻详情点击事件
		mui(".newslist").on('tap','a',function(){		 
			//获取id
			var nid = this.getAttribute("id");
	    	mui.openWindow({url:"news.html",id:nid,extras:{nid:nid}});
	  		var  readed_nids = tzdr.cacheNews.getData(tzdr.cacheNews.readed_nids);
	  		
	  		if (mui.isnull(readed_nids)){
	  			tzdr.cacheNews.setData(tzdr.cacheNews.readed_nids,nid)
	  		}
	  		else
	  		{   if (!tzdr.cacheNews.isread(nid)){
	  				tzdr.cacheNews.setData(tzdr.cacheNews.readed_nids,readed_nids+","+nid);
	  			}
	  		}
	  		//新增已读样式
	  		this.className+=' nl_read';
	  		
		});
		
	}
	if (mui.os.plus) {
		mui.plusReady(function() {
			setTimeout(function() {
				mui('#pullrefresh').pullRefresh().pullupLoading();
			}, 1000);
			switch (plus.os.name){
				case "Android":
					break;
				case "iOS":
				var newslist = document.getElementById('pullrefresh');
				newslist.style.paddingTop = '44px';
					break;
				default:
					break;
			}
		});
	} else {
		mui.ready(function() {
			mui('#pullrefresh').pullRefresh().pullupLoading();
		});
	}
	document.getElementById("back").addEventListener("tap",function(){
    			mui.app_back("home",true);
    		});
	document.getElementById("telBtn").addEventListener("tap",function(){
		mui.callService();
	});
</script>
</body>
</html>